package com.btashov.stringarray;

/**
 * @author Bahtiyar Tashov <btashov@gmail.com>
 */

/**
 * todo: Check if one string is a rotation of other string
 *
 * First make sure s1 and s2 are of the same length.
 * Then check to see if s2 is a substring of s1 concatenated with s1:
 * <p/>
 * <pre><code>
 *  algorithm checkRotation(string s1, string s2)
 *      if( len(s1) != len(s2))
 *          return false
 *      if( substring(s2,concat(s1,s1))
 *          return true
 *      return false
 *  end
 * <code/><pre/>
 */
public class Rotation {


    //todo: cover with test
    public boolean isRotation(String s1, String s2) {
        return (s1.length() == s2.length()) && ((s1 + s1).indexOf(s2) != -1);
    }
}
